// ***********************************************************
//
//   cc_main.h - main class containing results
//
//   REVISION  DATE    AUTHOR				MODIFICATION
//   Rev-1    Fall 07   WHH (Wen-Hsin Hsieh) Original author, CSSE
//   Rev-2    9/13/08   VN                  Added CS_ASP_S
//   Rev-3    3/15/09   KCV            Replaced WEB_ASP_* to WEB_ASP_JSP_*
//                                     to include JSP
// ***********************************************************

#ifndef cc_main_h
#define cc_main_h	1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include <map>
#include <stack>
#include <algorithm>
using namespace std;

#define PRODUCT_REVISION "200909"

#define PHY		0
#define LOG		1
#define CODE	0
#define DATA	1

#define QUOTE_CHAR            '\''
#define BLANK				   ' '
#define FF_CHAR               '\f'  // This character is a Form Feed.
#define TAB_CHAR              '\t'  // This character is a TAB.
#define CR_CHAR               '\r'  // This character is a carriage return.

#define MAX_LINE_LENGTH		  10485760

#define DATAFILE			  0		// data file type
#define C_CPP				  1		// C/C++
#define JAVA				  2		// Java
#define JAVA_JSP			  3		// Java	in JSP
#define CSHARP				  4		// C#
#define CSHARP_HTML			  5		// C# in HTML
#define WEB					  6     // WebCounter
#define VB					  7     // VB
#define VBS_PHP				  8     // VBScript in PHP
#define VBS_HTML			  9     // VBScript in HTML
#define VBS_JSP				  10    // VBScript in JSP
#define VBS_ASP_S			  11    // VBScript server side in ASP
#define VBS_ASP_C			  12    // VBScript client side in ASP
#define	HTML				  13    // Html
#define	HTML_PHP			  14    // Html in PHP
#define	HTML_JSP			  15    // Html in JSP
#define	HTML_ASP			  16    // Html in ASP
#define	JAVASCRIPT			  17    // Javascript
#define	JAVASCRIPT_PHP		  18    // Javascript in PHP
#define	JAVASCRIPT_HTML		  19    // Javascript in HTML
#define	JAVASCRIPT_JSP		  20    // Javascript in JSP
#define	JAVASCRIPT_ASP_S	  21    // Javascript server side in ASP
#define	JAVASCRIPT_ASP_C	  22    // Javascript client side in ASP
#define	PHP					  23    // php
#define	ADA					  24    // ada
#define	SQL					  25    // sql
#define	PERL				  26    // perl
#define CS_ASP_S			  27    // C# server side in ASP
#define	CSS				      28    // css
#define COLDFUSION			  29	//ColdFusion Counter

//the text that appears in output file for each web language
//please set the index corresponds to the define above.
//for web counter only
const char WEB_LANGUAGE_NAME[27][30] = { "<error>",
										 "<error>",
										 "<error>",
										 "<JSP>",
										 "<error>",
										 "<C#>",
										 "<error>",
										 "<error>",
										 "<VBS/PHP>",
										 "<VBS/HTML>",
										 "<VBS/JSP>",
										 "<VBS/ASP server>",
										 "<VBS/ASP client>",
										 "<HTML>",
										 "<HTML/PHP>",
										 "<HTML/JSP>",
										 "<HTML/ASP>",
										 "<error>",
										 "<JavaScript/PHP>",
										 "<JavaScript/HTML>",
										 "<JavaScript/JSP>",
										 "<JavaScript/ASP server>",
										 "<JavaScript/ASP client>",
										 "<PHP>",
										 "<error>",
										 "<error>",
										 "<error>",
};

#define DEF_LANG_NAME		  "UNDEF"

#define input_file_list_name  "filelist.dat"
#define output_file_name      "_outfile.dat"
#define output_file_name_old  "results.dat"
#define output_file_cplx	  "outfile_cplx.txt"
#define LOG_FILENAME		  "log.dat"

///////////////////////////////////////////////////////
// For WebCounter Only
///////////////////////////////////////////////////////

#define	WEB_PHP_START		0
#define	WEB_PHP_END			1
#define	WEB_SCRIPT_START	2
#define	WEB_SCRIPT_END		3
#define	WEB_ASP_JSP_START	4  // KCV: changed to include JSP as well
#define	WEB_ASP_JSP_END		5  // KCV: changed to include JSP as well
#define	WEB_PHP_START2		6

///////////////////////////////////////////////////////
// 1. General Data Structures
///////////////////////////////////////////////////////

struct lineElement
{
	lineElement(int num, string str)
	{
		lineNumber = num;
		line = str;
	}
	lineElement()
	{
		lineNumber = 0;
		line = "";
	}
	int    lineNumber;
	string line;
};

typedef vector<lineElement> filemap;

typedef map<string,int> srcLineVector;	// Diff Purposes

// struct to hold results for each files
class results
{
public:

	results(){reset();}

	string error_code;				// error string
	int    blank_lines;				// # of blank lines
	int    comment_lines;			// # of whole line comment lines
	int    e_comm_lines;			// # of embedded comment lines
	int    directive_lines[2];		// # of compiler directive lines
	int    data_lines[2];			// # of data declaration lines
	int    exec_lines[2];			// # of executable lines
	int    SLOC_lines[2];			// # of SLOC lines
	int    total_lines;				// # of total lines	
	int	   cmplx_math_lines;		// # of Math function call lines (MMG)
	int	   cmplx_trig_lines;		// # of trig function call lines (MMG)
	int	   cmplx_logrithm_lines;	// # of logarithm function call lines (MMG)
	int	   cmplx_calc_lines;		// # of calculations (MMG)
	int	   cmplx_cond_lines;		// # of conditionals (MMG)
	int	   cmplx_logic_lines;		// # of logical operations (MMG)
	int	   cmplx_prepoc_lines;		// # of Preproc Directive lines for complexity (MMG)
	int	   cmplx_assign_lines;		// # of assignments (MMG)
	int	   cmplx_pointer_lines;		// # of pointer (RST)
	int    trunc_lines;				// # of truncated logical lines
	bool   e_flag;					// set to true if error occurs during processing
	string file_name;
	int    file_type;
	unsigned int class_type;	//Mod042909AS
	size_t lsloc_truncate;

	// Diff Vars
	bool duplicate;	
	srcLineVector mySLOCLines;	//Contains the actual logical lines of code for diffing
	void addSLOC(string line, bool &trunc_flag) {
		pair<srcLineVector::iterator,bool> insertResult = mySLOCLines.insert(make_pair(line,1));
		if (!insertResult.second) {	//Element already exists
			(*insertResult.first).second++;	//Update number of times this SLOC exists
		}
		if (trunc_flag)
		{
			trunc_lines++;
			trunc_flag = false;
		}
	}
	results& operator= (const results&);
	void reset();
};

typedef pair<filemap, results> SourceFileElement;

typedef vector<string>  StringVector;
typedef pair<int, int>  IntPair;
typedef vector<IntPair> IntPairVector;

#endif
